package day240802.e3;

public class ThreadDeadlockExample {
    private static Object lock1 = new Object();
    private static Object lock2 = new Object();

    public static void main(String[] args) {
        // 模拟死锁
        Thread thread1 = new Thread(() -> {
            synchronized (lock1) {
                System.out.println("thread1 acquired lock1");
                synchronized (lock2){
                    System.out.println("thread1 成功进入WC");
                }
            }
        });
        Thread thread2 = new Thread(() -> {
            synchronized (lock2) {
                System.out.println("thread2 acquired lock2");
                synchronized (lock1){
                    System.out.println("thread2 成功进入WC");
                }
            }
        });
        thread1.start();
        thread2.start();
    }
}
